﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TomShane.Neoforce.Controls;
using RebEngine.Managers;
using RebellionII.GameObjects.Map;

namespace RebellionII.GUI
{
    public class BuildPopup: Window
    {
        public BuildPopup(RebSystem thisSystem, string type)
            :base(InputManager.Manager)
        {
            Init();
            Center();
            Height = 37;
            Width = 160;
            Resizable = false;
            BorderVisible = false;
            AutoScroll = false;
            Movable = true;
            Name = thisSystem.sName + " Popup";

            Label name = new Label(InputManager.Manager);
            name.Init();
            name.Left = 5;
            name.Top = 6;
            name.Height = 13;
            name.Width = 120;
            Add(name);

            Label quantityToBuild = new Label(InputManager.Manager);
            quantityToBuild.Init();
            quantityToBuild.Left = 5;
            quantityToBuild.Top = 24;
            quantityToBuild.Height = 13;
            quantityToBuild.Width = 120;
            
            Add(quantityToBuild);

            Label timeToNextCompletion = new Label(InputManager.Manager);
            timeToNextCompletion.Init();
            timeToNextCompletion.Left = 5;
            timeToNextCompletion.Top = 42;
            timeToNextCompletion.Height = 13;
            timeToNextCompletion.Width = 120;
            Add(timeToNextCompletion);

            ProgressBar timeBar = new ProgressBar(InputManager.Manager);
            timeBar.Init();
            timeBar.Left = 0;
            timeBar.Top = 63;
            timeBar.Height = 12;
            timeBar.Width = Width;
            Add(timeBar);

            
            switch (type)
            {
                case "Facility":
                    name.Text = NetClientManager.UnitList[thisSystem.FacilityBuildReferenceID].sName;
                    quantityToBuild.Text = "Quantity: " + thisSystem.FacilityBuildQuantity;
                    timeToNextCompletion.Text = "Remaining: " + (thisSystem.FacilityBuildTotalCost - thisSystem.FacilityBuildCurrentProgress);
                    timeBar.Range = thisSystem.FacilityBuildTotalCost;
                    timeBar.Value = thisSystem.FacilityBuildCurrentProgress;
                    break;

                case "Ship":
                    name.Text = NetClientManager.UnitList[thisSystem.ShipBuildReferenceID].sName;
                    quantityToBuild.Text = "Quantity: " + thisSystem.ShipBuildQuantity;
                    timeToNextCompletion.Text = "Remaining: " + (thisSystem.ShipBuildTotalCost - thisSystem.ShipBuildCurrentProgress);
                    timeBar.Range = thisSystem.ShipBuildTotalCost;
                    timeBar.Value = thisSystem.ShipBuildCurrentProgress;
                    break;

                case "Troop":
                    name.Text = NetClientManager.UnitList[thisSystem.TroopBuildReferenceID].sName;
                    quantityToBuild.Text = "Quantity: " + thisSystem.TroopBuildQuantity;
                    timeToNextCompletion.Text = "Remaining: " + (thisSystem.TroopBuildTotalCost - thisSystem.TroopBuildCurrentProgress);
                    timeBar.Range = thisSystem.TroopBuildTotalCost;
                    timeBar.Value = thisSystem.TroopBuildCurrentProgress;
                    break;

            }
            InputManager.Manager.Add(this);
        }
    }
}
